package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckGroupDao;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckGroupServiceImpl implements CheckGroupService {
    @Autowired
    private CheckGroupDao checkGroupDao;
    @Override
    public void add(CheckGroup checkGroup, List<Long> ids) {
        checkGroupDao.add(checkGroup);
        //checkGroupDao.addties(ids);
    }

    @Override
    public void deleteById(Long id) {
        checkGroupDao.deleteById(id);
    }

    @Override
    public List<String> findCheckGroupIdsBySetmealId(Long setmealId) {
        return checkGroupDao.findCheckGroupIdsBySetmealId(setmealId);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //下一条sql进行分页，自动加入limit关键字分页
        Page<CheckGroup> page = checkGroupDao.pageQuery(queryPageBean);
        return new PageResult(page.getTotal(), page.getResult());
    }
    /*修改检查组*/
    @Override
    public void edit(CheckGroup checkGroup, List<Long> ids) {
        checkGroupDao.edit(checkGroup);
        Integer checkGroupId=checkGroup.getId();
        checkGroupDao.deleteties(checkGroupId);
        checkGroupDao.addties(checkGroupId,ids);
    }
    /*查询所有检查组*/
    @Override
    public List<CheckGroup> findAll() {
        return checkGroupDao.findAll();
    }
    /*根据id查询检查组*/
    @Override
    public CheckGroup findById(Long id) {
        return checkGroupDao.findById(id);
    }
}
